﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NAnt.Core;
using NAnt.Core.Attributes;
using NAnt.Core.Types;
using System.Data.OleDb;

namespace NAntExt.Tasks
{
    /// <summary>
    /// Lists all the processes which match the inputs.
    /// </summary>
    [TaskName("process-list")]
    public class ProcessListTask : ProcessTaskBase
    {
        /// <summary>
        /// Entry point for the task.
        /// </summary>
        protected override void ExecuteTask()
        {
            try
            {
                var processes = GetProcesses();
                if (processes.Count == 0)
                {
                    Log(Level.Info, "No processes found to list. {0}", GetInputInfo());
                }
                else
                {
                    Log(Level.Info, "{0} process(es) found. {1}", processes.Count, GetInputInfo());

                    foreach (var process in processes)
                    {
                        Log(Level.Info, GetProcessInfo(process));
                    }
                }
            }
            catch (Exception ex)
            {
                this.ThrowOrLog(this.Location, ex);
            }
        }
                                
    }
}
